// 给定一个链表的头节点head，要求判断该链表是否为回文链表

// 思路：双指针，把链表节点值存入数组中比较
// 时间复杂度：O(n) 
// 空间复杂度：O(n)

const { LinkedList, ListNode} = require('./64.设计链表')

function isPalindrome(head) {
    let arr = []
    let cur = head
    while (cur) {
        arr.push(cur.val)
        cur = cur.next
    }
    let left = 0
    let right = arr.length - 1
    while (left < right) {
        if (arr[left] !== arr[right]) {
            return false
        }
        left++
        right--
    }
    return true
}

let head = [1,2,2,1]
let node = new LinkedList(head)
console.log(isPalindrome(node.head))